﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core.Library;
using DataObject;
using DataObject.Category;
using DataObject.Product;

public partial class Controls_Product_Home_NewProduct : System.Web.UI.UserControl
{
    protected string strTagA = "<a href=\"{0}\" title=\"{1}\">{1}</a>";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rptProduct.DataSource = ProductController.Product_ListTopHightlightProduct(SettingValues.PageSize_4);
            rptProduct.DataBind();
        }    
    }

    protected void rptProduct_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            var categoryId = ConvertUtility.ToInt32(((HiddenField)e.Item.FindControl("hfCategoryId")).Value);
            var productId = ConvertUtility.ToInt32(((HiddenField)e.Item.FindControl("hfProductId")).Value);
            var title = ((HiddenField)e.Item.FindControl("hfTitle")).Value;

            var ltrTitle = ((Literal)e.Item.FindControl("ltrTitle"));
            var ltrShoppingCart = ((Literal)e.Item.FindControl("ltrShoppingCart"));
            var ltrImage = ((Literal)e.Item.FindControl("ltrImage"));

            var imgHref = "/images/products/home_2/1.jpg";// string.Format("{0}/Thumb.ashx?Id={1}&tId={2}&Size=190&Fix=highlight", Constants.ThumbImage, productId, (int)CategoryType.Product);
            

            var categoryName = CategoryController.GetCategoryName(categoryId);
            var pHref = UrlHelpers.ProductDetail(categoryName, ConvertUtility.ToInt32(productId), title);
            ltrTitle.Text = string.Format(strTagA, pHref, title);

            ltrShoppingCart.Text = "<a href=\"javascript:void(0);\" class=\"add-to-cart pull-left\" onclick=\"addToCart('" + productId + "')\"><i class=\"fa fa-shopping-cart\"></i></a><a class=\"beta-btn primary\" href=\"" + pHref + "\">Chi tiết <i class=\"fa fa-chevron-right\"></i></a>";

            ltrImage.Text = string.Format("<a href=\"{0}\" title=\"{1}\" class=\"thumb\"><img src=\"{2}\" alt=\"\" /></a>", pHref, title, imgHref); 
        }
    }
}